/*
   agregar FK para ctblibcta.id referida a ctblibcol.id

   (olvido en script anterior)

*/

ALTER TABLE ctblibcta ADD COLUMN idctblibcol integer;

UPDATE ctblibcta SET idctblibcol = ctblibcol.id
FROM 
ctblibcol  
WHERE ctblibcta.codctblib = ctblibcol.codctblib AND ctblibcta.nroctblibcol = ctblibcol.nro;

ALTER TABLE ctblibcta ALTER COLUMN idctblibcol SET NOT NULL;
     
ALTER TABLE ctblibcta ADD CONSTRAINT gestion_ai_ctblibcolctblibcta_id FOREIGN KEY (idctblibcol)
      REFERENCES ctblibcol (id) MATCH SIMPLE
      ON UPDATE CASCADE ON DELETE CASCADE;

-- =================================
SELECT aaVersion('466.00','465.03');
-- =================================